<script>
    upFile:function(){
        var me=this;
        var msg=me.msg;
        var serverUrl = me.serverUrl;
        uni.chooseImage({
            count: 4, //默认9
            sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
            sourceType: ['album'], //从相册选择
            success: (chooseImageRes) => {
                const tempFilePaths = chooseImageRes.tempFilePaths; //这里用数组保存选择的单个或多个文件
                for ( var i = 0; i < tempFilePaths.length; i++) {
                    uni.uploadFile({ //循环调用上传单个文件的接口,实现多文件上传
                        url: serverUrl + '/ddkbishe/user/baoxiu/uploads', //仅为示例，非真实的接口地址
                        filePath: tempFilePaths[i],
                        formData: {
                            'msg': me.msg,
                            'housecode':me.globalUser.housecode,
                            'eleappname':me.eleappname
                        },
                        name: 'file',
                        success:(res) => {
                            if(me.eleappname==''){
                                uni.showToast({
                                    title: '请选择用电器',
                                    image: "../../static/icos/error.png",
                                    duration: 2000
                                });
                            }else if(me.msg==''){
                                uni.showToast({
                                    title: '请说明情况',
                                    image: "../../static/icos/error.png",
                                    duration: 2000
                                });
                            }else{
                                uni.showToast({
                                    title: '图片上传成功',
                                    mask: true,
                                    duration: 1000
                                });
                                uni.redirectTo({
                                    url:"../mybaoxiu/mybaoxiu"
                                })
                            }
                        }
                    });
                }
            },fail:function(chooseImageRes){
                uni.showToast({
                    title: '取消上传图片',
                    duration: 1000,
                    image: "../../static/icos/error.png"
                })
            }
        });
    },
    selecteleappname(){
        var me=this;
        var serverUrl = me.serverUrl;
        uni.request({
            url: serverUrl + '/ddkbishe/ddkbishe/eleapp/list' ,
            method: "GET",
            success: (res) => {
                //获取真实数据之前，务必判断状态是否为200
                console.log(res)
                if (res.data.code === 20000) {
                    me.eleapps=res.data.data.items;
                }

                uni.setStorageSync("eleapps", me.eleapps)
                uni.navigateTo({
                    url: "../selecteleapp/selecteleapp"
                });
                uni.showToast({
                    title: "电器选择页面",
                    mask: true,
                    duration: 1000
                });

            }
        });
    }
    },
</script>

